home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Information / CSMP Digest / volume 2 / csmp-v2-013.txt < prev    next >
Text File  |  1995-06-30  |  40KB  |  1,047 lines

  1. C.S.M.P. Digest             Tue, 16 Feb 93       Volume 2 : Issue 13
  2.  
  3. Today's Topics:
  4.  
  5.     Think C Debugger Voracity
  6.     TCL, MultiFinder, and Progress Dialogs
  7.     Completion proc stuff
  8.     QuickDraw: Why Can't it Mirror Right?
  9.     My MyDoubleBackProc() is too slow!!
  10.  
  11.  
  12.  
  13. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  14.  
  15. The digest is a collection of article threads from the internet newsgroup
  16. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  17. regularly and want an archive of the discussions.  If you don't know what a
  18. newsgroup is, you probably don't have access to it.  Ask your systems
  19. administrator(s) for details.  If you don't have access to news, you can
  20. post articles to any newsgroup by mailing your article to
  21.     newsgroup@cs.utexas.edu
  22. So, to post an article to comp.sys.mac.programmer, mail your article to
  23.     comp-sys-mac-programmer@cs.utexas.edu
  24. Note the '-' instead of '.' in the newsgroup name.  Be sure to ask that
  25. replies be emailed to you instead of posted to the group, and give your
  26. email address.
  27.  
  28. Each issue of the digest contains one or more sets of articles (called
  29. threads), with each set corresponding to a 'discussion' of a particular
  30. subject.  The articles are not edited; all articles included in this digest
  31. are in their original posted form (as received by our news server at
  32. cs.uoregon.edu).  Article threads are not added to the digest until the last
  33. article added to the thread is at least one month old (this is to ensure that
  34. the thread is dead before adding it to the digest).  Article threads that
  35. consist of only one message are generally not included in the digest.
  36.  
  37. The entire digest is available for anonymous ftp from ftp.cs.uoregon.edu
  38. [128.223.8.8] in the directory /pub/mac/csmp-digest.  Be sure to read the
  39. file /pub/mac/csmp-digest/README before downloading any files.  The most
  40. recent issues are available from sumex-aim.stanford.edu [36.44.0.6] in the
  41. directory /info-mac/digest/csmp.  If you don't have ftp capability, the sumex
  42. archive has a mail server; send a message with the text '$MACarch help' (no
  43. quotes) to LISTSERV@ricevm1.rice.edu for more information.
  44.  
  45. The digest is also available via email.  Just send a note saying that you
  46. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  47. automatically receive each new issue as it is created.  Sorry, back issues
  48. are not available through the mailing list.
  49.  
  50. Send administrative mail to mkelly@cs.uoregon.edu.
  51.  
  52.  
  53. -------------------------------------------------------
  54.  
  55. From: urban@yoda.fsl.noaa.gov (Art Urban)
  56. Subject: Think C Debugger Voracity
  57. Date: 12 Jan 93 23:11:56 GMT
  58. Organization: Forecast Systems Lab, NOAA, Boulder CO, USA
  59.  
  60. In a sentence:
  61.  
  62. How much bloody memory does the voracious debugger need! :-)
  63.  
  64. I'm currently up to 2Meg, and the dang thing *still* exceeds it. I did
  65. notice that after each Step command I issue, the Debugger consumes 50k+(!)
  66. of its own heap. Everything its consuming is "unlocked" according to
  67. Swatch, but apparently it can't purge anything. 
  68.  
  69. So what's a programmer to do?
  70.  
  71. - -- 
  72. Art Urban                             urban@yoda.fsl.noaa.gov
  73. ===============================================================================
  74.  "Look, he's being attacked by creamy nugget centers."              -Joel
  75. ===============================================================================
  76.  
  77. +++++++++++++++++++++++++++
  78.  
  79. From: flc3527@zeus.tamu.edu (CAMPBELL, FRED LELAND)
  80. Date: 13 Jan 93 05:38:00 GMT
  81. Organization: Texas A&M University, Academic Computing Services
  82.  
  83. In article <1993Jan12.231156.1576@fsl.noaa.gov>, urban@yoda.fsl.noaa.gov (Art Urban) writes...
  84. >I'm currently up to 2Meg, and the dang thing *still* exceeds it. I did
  85. >notice that after each Step command I issue, the Debugger consumes 50k+(!)
  86. >of its own heap. Everything its consuming is "unlocked" according to
  87. >Swatch, but apparently it can't purge anything. 
  88. >So what's a programmer to do?
  89.  
  90. Are you using Desktop Textures or something like it to give you those really
  91. neat desktop patterns? I had a similar problem recently and remembered
  92. reading somewhere (here or think-c?) that when the debuggers steps through
  93. code it copies something to do with the extended desktop pattern and this eats
  94. up memory like crazy. I stopped using Desktop Textures and my problem went
  95. away, your mileage may vary. (Note, I only had the problem when I was stepping
  96. through code). Of course, this is just a guess.
  97. Trey.
  98.  
  99. +++++++++++++++++++++++++++
  100.  
  101. From: lari@cs.unc.edu (Humayun Lari)
  102. Date: 13 Jan 1993 18:32:08 -0500
  103. Organization: The University of North Carolina at Chapel Hill
  104.  
  105. In article <1993Jan12.231156.1576@fsl.noaa.gov> urban@yoda.fsl.noaa.gov (Art Urban) writes:
  106. >How much bloody memory does the voracious debugger need! :-)
  107. >
  108. >I'm currently up to 2Meg, and the dang thing *still* exceeds it. I did
  109. >notice that after each Step command I issue, the Debugger consumes 50k+(!)
  110. >of its own heap. Everything its consuming is "unlocked" according to
  111. >Swatch, but apparently it can't purge anything. 
  112.  
  113. If you're using a large color pixel pattern on your desktop, the current
  114. THINK C debugger has a bug that causes it to make a copy of the pattern every
  115. time you step. This can use up a lot of memory. (Note that I could be wrong
  116. about some detail or other, since this is off the top of my head.)
  117.  
  118. If not, I'm stumped.
  119.  
  120. Humayun Lari
  121. (lari@cs.unc.edu)
  122.  
  123.  
  124. ---------------------------
  125.  
  126. From: rrichter@link.ph.gmr.com (Roy Richter PH/32)
  127. Subject: TCL, MultiFinder, and Progress Dialogs
  128. Date: 11 Jan 93 18:30:40 GMT
  129. Organization: GM Research and Environmental Staff
  130.  
  131. I want to have a progress dialog up for an operation that takes
  132. over a minute, so I've got the usual text string, and a horizontal
  133. bar that fills up as the operation proceeds.  It would be nice to
  134. also:
  135.  
  136. (1) let the Multifinder take time slices to update other programs,
  137.     I assume that WaitNextEvent will do it;
  138. (2) Have a "Cancel" button the user can push to cancel the 
  139.     operation.  This has me stuck.
  140.  
  141. I use the Class Library to manage the dialogs.  That way, I just
  142. GetGoodClicks and so on.  In this case, I'm not passing control up the
  143. line to let the DeskTop get the click and dispatch it.  I wouldn't want
  144. to break up my operation into a bunch of Tasks, that would be
  145. hard--since I'm updating the progress dialog in a callback.  I'd prefer
  146. the MultiFinder timeout and clicks be self-contained in the callback.
  147. That was I can use the callback in many places, as needed.  Otherwise
  148. I'd need to restucture the code into a Task everytime I thought a
  149. time-slice was needed.
  150.  
  151. Any hints?
  152.  
  153. - --
  154. Roy Richter                  Internet: rrichter@ph.gmr.com
  155. Physics Dept, GM Research    UUCP:     rphroy!rrichter
  156.  
  157. +++++++++++++++++++++++++++
  158.  
  159. From: stern@comb1.comb.umd.edu (Brian Stern; COMB)
  160. Date: 11 Jan 93 21:16:00 GMT
  161. Organization: University of Maryland, Center of Marine Biotechnology
  162.  
  163. In article <96290@rphroy.ph.gmr.com>, rrichter@link.ph.gmr.com (Roy Richter PH/32) writes...
  164. >I want to have a progress dialog up for an operation that takes
  165. >over a minute, so I've got the usual text string, and a horizontal
  166. >bar that fills up as the operation proceeds.  It would be nice to
  167. >also:
  168. >(1) let the Multifinder take time slices to update other programs,
  169. >    I assume that WaitNextEvent will do it;
  170. >(2) Have a "Cancel" button the user can push to cancel the 
  171. >    operation.  This has me stuck.
  172. >
  173. Call WNE with a mDownMask. If it returns true then call FindControl to get
  174. the control handle (pass it theEvent.where as the point) and then
  175. TrackControl. If TrackControl tells you that the mouseup occurred in
  176. your cancel button then go ahead and cancel the operation. Note that Apple
  177. now recommends a distinction between a 'Cancel' button and a 'Stop' button
  178. where the first results in a complete return to the conditions before the
  179. operation was started and the latter merely interuppts the operation. So if
  180. the operation were copying files 'cancel' would delete any files that had 
  181. been copied up to the point when the cancel button was hit and 'Stop' would
  182. leave any files which had already been copied but wouldn't copy any more.
  183.  
  184. Brian Stern
  185. Stern@mbimail.umd.edu
  186.  
  187. +++++++++++++++++++++++++++
  188.  
  189. Date: 11 Jan 93 21:56:03 GMT
  190. Organization: Royal Institute of Technology, Stockholm, Sweden
  191.  
  192. In <11JAN199316162844@comb1.comb.umd.edu> stern@comb1.comb.umd.edu (Brian Stern; COMB) writes:
  193.  
  194. >>I want to have a progress dialog up for an operation that takes
  195. >>over a minute, so I've got the usual text string, and a horizontal
  196.  
  197. >>(1) let the Multifinder take time slices to update other programs,
  198. >>    I assume that WaitNextEvent will do it;
  199. >>(2) Have a "Cancel" button the user can push to cancel the 
  200. >>    operation.  This has me stuck.
  201.  
  202. >Call WNE with a mDownMask. If it returns true then call FindControl to get
  203. >the control handle (pass it theEvent.where as the point) and then
  204. >TrackControl. If TrackControl tells you that the mouseup occurred in
  205.  
  206. Actually, this is a bad thing to do to a TCL app; for instance
  207. AppleEvents would be lost because they are ALWAYS delivered
  208. regardless of event mask.
  209.  
  210. Instead, I usually put up a movable, modal dialog with the bar
  211. etc, and when I need to give idle time, I do:
  212.  
  213.     gSleepTime = 0 ;
  214.     gApplication -> Process1Event ( ) ;
  215.  
  216. If you can set up an Idle chore to do the idling, you could
  217. even have your dialog be the supervisor of the chore and have
  218. BeginDialog and EndDialog handle dialog ending.
  219.  
  220. So what does this do? Well, you can't call DoModalDialog if you
  221. cannot push the thing you're doing into a chore; you'll have
  222. to mimic the behaviour in your idle call. What remains is to
  223. handle DoCommand ( cmdCancel ) by overriding it in the
  224. CDLOGDirector.
  225.  
  226. Hope this helps,
  227.  
  228.                             / h+
  229. - -- 
  230.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
  231.    This signature is kept shorter than 4 lines in the interests of UseNet
  232.    S/N ratio.
  233.  
  234. +++++++++++++++++++++++++++
  235.  
  236. From: athos@apple.com (Rick Eames)
  237. Date: 12 Jan 93 17:47:21 GMT
  238. Organization: Apple Computer, Inc.
  239.  
  240. In article <1993Jan11.215603.26274@kth.se>, d88-jwa@byse.nada.kth.se (Jon
  241. Wtte) wrote:
  242.  
  243. > Actually, this is a bad thing to do to a TCL app; for instance
  244. > AppleEvents would be lost because they are ALWAYS delivered
  245. > regardless of event mask.
  246. > Instead, I usually put up a movable, modal dialog with the bar
  247. > etc, and when I need to give idle time, I do:
  248. >     gSleepTime = 0 ;
  249. >     gApplication -> Process1Event ( ) ;
  250. > If you can set up an Idle chore to do the idling, you could
  251. > even have your dialog be the supervisor of the chore and have
  252. > BeginDialog and EndDialog handle dialog ending.
  253. > So what does this do? Well, you can't call DoModalDialog if you
  254. > cannot push the thing you're doing into a chore; you'll have
  255. > to mimic the behaviour in your idle call. What remains is to
  256. > handle DoCommand ( cmdCancel ) by overriding it in the
  257. > CDLOGDirector.
  258.  
  259. The problem with this method is that your damned cursor ends up resetting
  260. to a pointer each time you Process1Event() so you have to override that too
  261. to ensure that your nice spinning cursor works.
  262.  
  263. ############################################################################
  264. Rick Eames                         Internet:      athos@apple.com
  265. Apple Computer, Inc.               CompuServe:    76666,2114
  266. My Opionions are my own.           AmericaOnline: EamesR
  267. "The Lord prefers common-looking people. That is why he makes so many of
  268. them."  - Lincoln
  269.  
  270. "But you know what?  There's another point that I'd like to make: it's very
  271. possible that Adolf Hitler kept a very nice check book.  You know?  I mean,
  272. and that's fine."  -- Barbara Boxer, Bill Press Show, KFI, 10/24/92
  273. ############################################################################
  274.  
  275. +++++++++++++++++++++++++++
  276.  
  277. From: joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91)
  278. Date: 12 Jan 93 20:21:47 GMT
  279. Organization: NASA/ARC Information Sciences Division
  280.  
  281. In article <96290@rphroy.ph.gmr.com> rrichter@link.ph.gmr.com (Roy Richter PH/32) writes:
  282. >I want to have a progress dialog up for an operation that takes
  283. >over a minute, so I've got the usual text string, and a horizontal
  284. >bar that fills up as the operation proceeds.  It would be nice to
  285. >also:
  286. >
  287. >(1) let the Multifinder take time slices to update other programs,
  288. >    I assume that WaitNextEvent will do it;
  289. >(2) Have a "Cancel" button the user can push to cancel the 
  290. >    operation.  This has me stuck.
  291. >
  292. >I use the Class Library to manage the dialogs.  That way, I just
  293. >GetGoodClicks and so on.  In this case, I'm not passing control up the
  294. >line to let the DeskTop get the click and dispatch it.  I wouldn't want
  295. >to break up my operation into a bunch of Tasks, that would be
  296. >hard--since I'm updating the progress dialog in a callback.  I'd prefer
  297. >the MultiFinder timeout and clicks be self-contained in the callback.
  298. >That was I can use the callback in many places, as needed.  Otherwise
  299. >I'd need to restucture the code into a Task everytime I thought a
  300. >time-slice was needed.
  301. >
  302. >Any hints?
  303. >
  304. >--
  305. >Roy Richter                  Internet: rrichter@ph.gmr.com
  306. >Physics Dept, GM Research    UUCP:     rphroy!rrichter
  307.  
  308.  
  309. One really sloppy method that I cannot see anyone recommending 
  310. (discussion ?) is to call WaitNextEvent from within a loop,
  311. masking out all events so they remain in the queue until
  312. the appropriate time.  
  313. But I don't think this is good.
  314.  
  315. An easier (but not great) way to handle cancels
  316. is to use GetKeys and check for command-period.
  317.  
  318. I have code to do this if anyone wants.  The problem is that it will not 
  319. work properly with some alternate keyboard systems (?) and 
  320. inits (?)  (I think.  Check the Develop article where someone
  321.           talks about repetitive strain injury and has to 
  322.           'type' with her feet.)
  323.  
  324.  
  325.  
  326.  
  327.  
  328. - -- 
  329. - ----------------------------------
  330. #include <std/disclaimer.h>     Josh Rabinowitz, Mac TCL programmer
  331. joshr@kronos.arc.nasa.gov
  332. "Me lost my cookie at the disco." -- Cookie Monster
  333.  
  334. +++++++++++++++++++++++++++
  335.  
  336. Organization: Royal Institute of Technology, Stockholm, Sweden
  337. Date: Thu, 14 Jan 1993 17:33:19 GMT
  338.  
  339. In <athos-120193094621@athos.apple.com> athos@apple.com (Rick Eames) writes:
  340.  
  341. >The problem with this method is that your damned cursor ends up resetting
  342. >to a pointer each time you Process1Event() so you have to override that too
  343. >to ensure that your nice spinning cursor works.
  344.  
  345. No, you can also override the cursor dispatch mechanism.
  346. I don't remember it offhand, but it's probably a much better
  347. place to do it.
  348.  
  349. {20-line .sig deleted}
  350.  
  351. Using 20 lines of .sig means showing no respect for people
  352. with 2400 baud modems.
  353.  
  354. Cheers,
  355.  
  356.                             / h+
  357. - -- 
  358.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
  359.  
  360.    There's no problem that can't be solved using brute-force algorithms
  361.    and a sufficiently fast computer. Ergo, buy more hardware.    (NOT!)
  362.  
  363. +++++++++++++++++++++++++++
  364.  
  365. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  366. Organization: Kalamazoo College
  367. Date: Thu, 14 Jan 1993 19:49:46 GMT
  368.  
  369. tte) writes:
  370. >athos@apple.com (Rick Eames) writes:
  371. >
  372. >>The problem with this method is that your damned cursor ends up resetting
  373. >>to a pointer each time you Process1Event() so you have to override that too
  374. >>to ensure that your nice spinning cursor works.
  375. >
  376. >No, you can also override the cursor dispatch mechanism.
  377. >I don't remember it offhand, but it's probably a much better
  378. >place to do it.
  379.  
  380. Yep, CDesktop::DispatchCursor() is the method to override.  See my
  381. CAnimCursor, ftp'able from ftp.brown.edu or sumex-aim.stanford.edu,
  382. for details.  Roughly, my CAcurDesktop::DispatchCursor() method
  383. looks like this:
  384.  
  385. if (the cursor is spinning and it wants to keep spinning smoothly) {
  386.     if (gInBackground || !CrsrVis) {
  387.     return;
  388.     }
  389.     CView::cCurrHelpView = NULL;
  390.     gAnimCursor->animateCursor();    // This spins the cursor, if it's
  391.                     // appropriate to do so
  392. } else {
  393.     inherited::DispatchCursor();
  394. }
  395.  
  396.  
  397. Hmmm, another article looking for a home in comp.sys.mac.oop.tcl...
  398. - -- 
  399.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  400.  "A degree in Computer Science from Berkeley didn't much qualify me to uphold
  401.   the banner of Chaos against the forces of Order."              - R. Zelazny
  402.  
  403. ---------------------------
  404.  
  405. From: davidp@stealth.usc.edu (David Peterson)
  406. Subject: Completion proc stuff
  407. Date: 12 Jan 93 09:19:42 GMT
  408. Organization: University of Southern California, Los Angeles, CA
  409.  
  410.  
  411.  
  412. I wrote a network copy program and thought I'd be clever and chain completion
  413. procs together to handle the I/O in order to keep the process invisible to the
  414. rest of the Mac. ie: receive completion does a write, write completion does a
  415. recieve, and the Mac still responds to me.
  416.  
  417. Well, it works great except that it hangs the machine for the duration of the
  418. copy. The mouse still moves around the screen and events still get posted, but
  419. they don't get processed until the copy is finished.
  420.  
  421. What gives? Do I have to suspend my completion proc chain momentarily to give
  422. the system time to do other stuff? I thought that by doing things asyncronously
  423. the I/O stuff would go on in the background leaving the machine free to handle
  424. user events.
  425.  
  426. By chaining things together like that did I just create one monster interupt
  427. routine, or does the rest of the system get time when I go through PBControl?
  428.  
  429. Did I screw up my code or my thinking? (or both)
  430.  
  431. If it matters, I'm going from MacTCP to the File Manager under 7.1.
  432.  
  433. - -dave.
  434.  
  435. +++++++++++++++++++++++++++
  436.  
  437. From: absurd@apple.apple.com (Tim Dierks, software saboteur)
  438. Date: 13 Jan 93 21:42:05 GMT
  439. Organization: MacDTS Marauders
  440.  
  441. In article <1ivqneINN609@stealth.usc.edu>, davidp@stealth.usc.edu (David
  442. Peterson) wrote:
  443. > I wrote a network copy program and thought I'd be clever and chain completion
  444. > procs together to handle the I/O in order to keep the process invisible to the
  445. > rest of the Mac. ie: receive completion does a write, write completion does a
  446. > recieve, and the Mac still responds to me.
  447. > Well, it works great except that it hangs the machine for the duration of the
  448. > copy. The mouse still moves around the screen and events still get posted, but
  449. > they don't get processed until the copy is finished.
  450. > What gives? Do I have to suspend my completion proc chain momentarily to give
  451. > the system time to do other stuff? I thought that by doing things asyncronously
  452. > the I/O stuff would go on in the background leaving the machine free to handle
  453. > user events.
  454. > By chaining things together like that did I just create one monster interupt
  455. > routine, or does the rest of the system get time when I go through PBControl?
  456. > Did I screw up my code or my thinking? (or both)
  457. > If it matters, I'm going from MacTCP to the File Manager under 7.1.
  458. > -dave.
  459.  
  460. I think your problem is basically that the Mac SCSI manager is currently
  461. synchronous; if you do a write to the disk, that call does not return
  462. until all the data has been written.  Thus, what I think is happening
  463. is:
  464.  
  465. 1) You do an async read from TCP
  466. 2) The async call to TCP returns
  467. 3) Eventually, the TCP read completes
  468. 4) Your TCP completion routine is called
  469. 5) You do an async write to the SCSI disk
  470. 6) All the data is written
  471. 7) Your completion routine is called
  472. 8) The async call to the disk driver returns
  473.  
  474. There are two important facts to be gleaned: 1) Because the disk driver
  475. is synchronous, your application doesn't execute while you're writing
  476. to the disk.  If your TCP data arrives quickly enough, you could actually
  477. keep the data arriving faster than it's being written out; this would
  478. cause your CPU to spend all of its time transferring data, with no time
  479. to service your application.
  480.  
  481. 2) Because the disk driver is synchronous, it does all of its data
  482. transfer when you make the Read() or Write() call, regardless of
  483. whether it is synchronous or asynchronous.  This means your completion
  484. routine is called before the asynchrounous call returns.  If it in
  485. turn make a new asynchronous call before finishing, that call's
  486. completion routine will be called before the Device Manager call
  487. returns; this could lead to reentrancy or stack usage problems if
  488. you're not extremely careful.  If you have this problem, the best way
  489. to deal with this is to defer posting new asynchronous requests until
  490. the stack has a chance to unwind itself, perhaps by using the Time
  491. Manager to post it later.  I don't think your case will have this
  492. problem because one half of your transfer is TCP-based, which is
  493. fully asynchronous, so it will give the routines some time to unwind.
  494. However, if your TCP data arrives fast enough so that your write can
  495. always be satisfied entirely out of the buffer, then your request may
  496. be completed immediately, giving you the same effect as a synchronous
  497. write.
  498.  
  499. Tim Dierks
  500. MacDTS, but I speak for myself
  501.  
  502. +++++++++++++++++++++++++++
  503.  
  504. Organization: Royal Institute of Technology, Stockholm, Sweden
  505. Date: Thu, 14 Jan 1993 17:29:21 GMT
  506.  
  507. In <1ivqneINN609@stealth.usc.edu> davidp@stealth.usc.edu (David Peterson) writes:
  508.  
  509.  
  510. >What gives? Do I have to suspend my completion proc chain momentarily to give
  511. >the system time to do other stuff? I thought that by doing things asyncronously
  512. >the I/O stuff would go on in the background leaving the machine free to handle
  513. >user events.
  514.  
  515. Well, it's like this:
  516.  
  517. The Mac SCSI driver doesn't support async calls.
  518.  
  519. If you do overlapping I/O, floppies and networks will give
  520. you reads while you write to disk, though.
  521.  
  522. - -- 
  523.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
  524.  
  525.    There's no problem that can't be solved using brute-force algorithms
  526.    and a sufficiently fast computer. Ergo, buy more hardware.    (NOT!)
  527.  
  528. ---------------------------
  529.  
  530. From: urban@yoda.fsl.noaa.gov (Art Urban)
  531. Subject: QuickDraw: Why Can't it Mirror Right?
  532. Date: 5 Jan 93 19:19:18 GMT
  533. Organization: Forecast Systems Lab, NOAA, Boulder CO, USA
  534.  
  535. There is something wrong with either QuickDraw or me... :-)
  536.  
  537. If I draw a line from 0,0 down and to the left, why won't QuickDraw mirror
  538. the line when I draw it down and to the *right*?
  539.  
  540. I've examined the resulting bitmaps by taking screenshots and looking at
  541. them in Canvas. The choices that QuickDraw makes for pixel placement are
  542. different, yet the lines begin and end in mirrored coordinates. No matter
  543. what I do, I cannot coerce QuickDraw to create a mirrored (pixel for pixel)
  544. line angle. I need this for a bisymetrical region I'm making, so I can't 
  545. just flip around some CopyBits operation (I presume).
  546.  
  547. I realize that mathematically my region will be defined correctly, but I
  548. want it to be drawn with some semblance of accuracy on the screen when I
  549. call FrameRgn(). If QuickDraw can do it correctly to the left, why can't it
  550. do it correctly to the right? (or vise-versa :-) )
  551.  
  552. - -- 
  553. Art Urban                             urban@yoda.fsl.noaa.gov
  554. ===============================================================================
  555.  "Look, he's being attacked by creamy nugget centers."              -Joel
  556. ===============================================================================
  557.  
  558. +++++++++++++++++++++++++++
  559.  
  560. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  561. Date: 5 Jan 93 22:31:22 GMT
  562. Organization: Kalamazoo College
  563.  
  564. urban@yoda.fsl.noaa.gov (Art Urban) writes:
  565. >There is something wrong with either QuickDraw or me... :-)
  566. >
  567. >If I draw a line from 0,0 down and to the left, why won't QuickDraw mirror
  568. >the line when I draw it down and to the *right*?
  569.  
  570. 'coz it doesn't use a very good algorithm.  QD always draws lines from
  571. top to bottom, but instead of splitting the horizontal error equally
  572. along the line, it biases it.  Are you getting a bias toward the top
  573. when you draw left and a bias toward the bottom when you draw right?
  574. (Just a guess.)
  575.  
  576. >No matter
  577. >what I do, I cannot coerce QuickDraw to create a mirrored (pixel for pixel)
  578. >line angle.
  579.  
  580. Nope.  You can't.  Even if you could, I heard someone making noises
  581. about 7.1 drawing lines differently than all previous systems.  If true,
  582. you probably don't want to use lines to make regions where every pixel
  583. is important.
  584.  
  585. >I need this for a bisymetrical region I'm making, so I can't 
  586. >just flip around some CopyBits operation (I presume).
  587.  
  588. Well, when I needed a small hexagon region a few weeks ago, I ended up
  589. framing all the individual rectangles, top to bottom.  It's not pretty,
  590. but I only had to make it once, and the resulting region is exactly the
  591. same as if I did it with LineTo()s.  Except that it'll still be the same
  592. even when System 12 is released and LineTo(), instead of drawing
  593. straight lines, uses cubic splines which for technical reasons will only
  594. be able to _approximate_ straightness...
  595.  
  596. If your region is too big to fabricate with rectangles, I don't know
  597. what to tell you.  Anyone have any bright ideas?
  598. - -- 
  599.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  600.  "Estimated number of DOS viruses in existence today:  1,500
  601.   Number of Macintosh-based viruses:  Less than 40
  602.   New DOS viruses discovered in summer '92:  More than 100"   - ComputerWorld
  603.  
  604. +++++++++++++++++++++++++++
  605.  
  606. From: jmunkki@vipunen.hut.fi (Juri Munkki)
  607. Date: 5 Jan 93 21:59:48 GMT
  608. Organization: Helsinki University of Technology
  609.  
  610. In article <1993Jan5.191918.12324@fsl.noaa.gov> urban@yoda.fsl.noaa.gov (Art Urban) writes:
  611. >I realize that mathematically my region will be defined correctly, but I
  612. >want it to be drawn with some semblance of accuracy on the screen when I
  613. >call FrameRgn(). If QuickDraw can do it correctly to the left, why can't it
  614. >do it correctly to the right? (or vise-versa :-) )
  615.  
  616. Inside Macintosh often gives the impression that regions are infinitely
  617. accurate when it says that regions are a mathematical representation of
  618. areas. In fact, a region is really just a packed bitmap. The packing
  619. method happens to be patented by Apple, but it's not fancy or anything.
  620.  
  621. So, if QD draws a line "incorrectly", then the pixels in the region will
  622. also be incorrect in the same way.
  623.  
  624. I suggest that you try using a bitmap mask that you draw with polygons.
  625. It may be faster than using regions, although this depends on the situation.
  626.  
  627. - -- 
  628.   Juri Munkki                           Windsurf: fast sailing
  629.  jmunkki@hut.fi                          Macintosh: fast software
  630.  
  631. +++++++++++++++++++++++++++
  632.  
  633. From: rmah@panix.com (Robert Mah)
  634. Organization: PANIX Public Access Unix, NYC
  635. Date: Wed, 6 Jan 1993 07:28:46 GMT
  636.  
  637. In <1993Jan5.191918.12324@fsl.noaa.gov> urban@yoda.fsl.noaa.gov (Art Urban) writes:
  638.  
  639. >If I draw a line from 0,0 down and to the left, why won't QuickDraw mirror
  640. >the line when I draw it down and to the *right*?
  641.  
  642. The reason is that the coordinates you are passing to QuickDraw routines are
  643. NOT pixel locations.  They are the locations BETWEEN pixels.  
  644.  
  645. Thus, if you draw a line from (0,0) to (4,0), with a pensize of (1,1), it 
  646. will be 5 pixels long.  But if you draw (0,0) to (-4,0) with a pensize of 
  647. (1,1), the line will be still be 5 pixels long, but have a RIGHT location
  648. at coordinate 1.  The key is that the "pen" hangs down and to the right of
  649. the "pen location".  And LINE drawing takes place using the pen.
  650.  
  651. You should re-read the beginning of the Quickdraw chapter in IM-I for a 
  652. much clearer description of the graphics model used within QD.
  653.  
  654. Good luck,
  655. Rob
  656. - -- 
  657. [--------------------------------------------------]
  658. [  Robert S. Mah   |  "Every day an adventure,     ]
  659. [  rmah@panix.com  |   every moment a challenge."  ]
  660. [--------------------------------------------------]
  661.  
  662. +++++++++++++++++++++++++++
  663.  
  664. Organization: Royal Institute of Technology, Stockholm, Sweden
  665. Date: Wed, 6 Jan 1993 14:34:10 GMT
  666.  
  667. In <1993Jan5.191918.12324@fsl.noaa.gov> urban@yoda.fsl.noaa.gov (Art Urban) writes:
  668.  
  669. >If I draw a line from 0,0 down and to the left, why won't QuickDraw mirror
  670. >the line when I draw it down and to the *right*?
  671.  
  672. Maybe because the pen has a physical size, and its centre is
  673. not placed on the grid intersection? Try setting the pen size
  674. (1,0) or (0,1) and see what happens.
  675.  
  676. Cheers,
  677.  
  678.                         / h+
  679. - -- 
  680.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
  681.  
  682.    Cookie Jar: Vanilla Yoghurt with Crushed Oreos.
  683.  
  684. +++++++++++++++++++++++++++
  685.  
  686. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  687. Date: 6 Jan 93 17:23:30 GMT
  688. Organization: Kalamazoo College
  689.  
  690. rmah@panix.com (Robert Mah) writes:
  691. >urban@yoda.fsl.noaa.gov (Art Urban) writes:
  692. >
  693. >>If I draw a line from 0,0 down and to the left, why won't QuickDraw mirror
  694. >>the line when I draw it down and to the *right*?
  695. >
  696. >The reason is that the coordinates you are passing to QuickDraw routines are
  697. >NOT pixel locations.  They are the locations BETWEEN pixels.  
  698. >
  699. >Thus, if you draw a line from (0,0) to (4,0), with a pensize of (1,1), it
  700. >will be 5 pixels long.  But if you draw (0,0) to (-4,0) with a pensize of
  701. >(1,1), the line will be still be 5 pixels long, but have a RIGHT location
  702. >at coordinate 1.  The key is that the "pen" hangs down and to the right of
  703. >the "pen location".  And LINE drawing takes place using the pen.
  704. >
  705. >You should re-read the beginning of the Quickdraw chapter in IM-I for a 
  706. >much clearer description of the graphics model used within QD.
  707.  
  708. And Jon Waette comments:
  709. >Maybe because the pen has a physical size, and its centre is
  710. >not placed on the grid intersection? Try setting the pen size
  711. >(1,0) or (0,1) and see what happens.
  712.  
  713. If I read Art correctly, he's not concerned about the pixels themselves;
  714. he's concerned about the region formed by his LineTo()s.  And, as IM
  715. I-181 says, "Only the line endpoints and shape boundaries affect the
  716. region definition;  the pen mode, pattern and size do not affect it."
  717.  
  718. The fact that the pen hangs down and right is irrelevant to region-
  719. building.  However, the way that the pixels are drawn will tell you how
  720. the region's boundaries are drawn.  Art is concerned, not that the
  721. pixels are drawn funny, but that his region will be built funny.  That's
  722. a problem with the way LineTo() chooses where to go, and that's not
  723. something you can cure by messing with the pen.  You _might_ be able to
  724. patch things up, to some degree, by picking your endpoints in an attempt
  725. to outsmart the algorithm, but that has nothing to do with the pen
  726. hanging one way or t'other.
  727.  
  728. Of course, maybe I read Art's question incorrectly...?  Art, I would
  729. advise testing out your region with the region itself, not by looking
  730. at the pixels drawn by the same set of LineTo()s--the two are not the
  731. same.
  732. - -- 
  733.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  734.  "Estimated number of DOS viruses in existence today:  1,500
  735.   Number of Macintosh-based viruses:  Less than 40
  736.   New DOS viruses discovered in summer '92:  More than 100"   - ComputerWorld
  737.  
  738. +++++++++++++++++++++++++++
  739.  
  740. From: bwilliam@iat.holonet.net (Bill Williams)
  741. Organization: HoloNet National Internet Access BBS: 510-704-1058/modem
  742. Date: Thu, 14 Jan 1993 07:44:52 GMT
  743.  
  744.  
  745.  
  746. IT IS TRUE that it comes as a shock to many when drawing a sweeping series of
  747. lines rotated about a single point that the moire pattern is distressingly
  748. non-symetric with the Macintoshes Line routine because of the way a point
  749. is defined in Inside Mac I.
  750.  
  751. I have no argument with it. With QuickDraw GX and other non-pixellated drawing
  752. systems it may indeed be a fine thing... but....
  753.  
  754. when I rewrote many Quickdraw routines from scratch for my own purposes
  755. (speed for animation) I rewrote the coordinate system such that lines and
  756. other items conformed to the center of the pixel boundaries not the
  757. intersecting edges.
  758.  
  759. I did this because I noticed that ugly moire patterns that were not
  760. symetrical and other such ugly things were eliminated.
  761.  
  762. Ah, peace at last.
  763.  
  764. I can understand the original authors felling of anger over his apparent
  765. misunderstanding of why Quickdraw works the way it does, or how to play
  766. games to get the lines to draw the way he wants (admittedly screwing up
  767. the bounds of his regions) but there are some people who reject apple's
  768. coordinate system altogether, like me for instance, and do not feel
  769. ashamed to say that centers of pixels are a better place for the point for
  770. the sake of symmetry alone.
  771.  
  772.  
  773. Bill Williams
  774.  
  775.  
  776. +++++++++++++++++++++++++++
  777.  
  778. Organization: Royal Institute of Technology, Stockholm, Sweden
  779. Date: Thu, 14 Jan 1993 18:26:50 GMT
  780.  
  781. In <C0u2ut.BLD@iat.holonet.net> bwilliam@iat.holonet.net (Bill Williams) writes:
  782.  
  783. >the bounds of his regions) but there are some people who reject apple's
  784. >coordinate system altogether, like me for instance, and do not feel
  785. >ashamed to say that centers of pixels are a better place for the point for
  786. >the sake of symmetry alone.
  787.  
  788. You want to build a fence; 100m, with fenceposts every 10
  789. meters. Now, how many posts do you need?
  790.  
  791. :-)
  792.  
  793. - -- 
  794.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
  795.    The word "politics" is derived from the word "poly", meaning
  796.    "many", and the word "ticks", meaning "blood sucking parasites".
  797.                      -- Larry Hardiman
  798.  
  799. +++++++++++++++++++++++++++
  800.  
  801. From: hpoppe@ncar.ucar.edu (Herb Poppe)
  802. Organization: Scientific Computing Division/NCAR Boulder, CO
  803. Date: Fri, 15 Jan 1993 16:29:57 GMT
  804.  
  805.  In <C0u2ut.BLD@iat.holonet.net> bwilliam@iat.holonet.net (Bill Williams) 
  806. writes:
  807.  
  808.  > the bounds of his regions) but there are some people who reject apple's
  809.  > coordinate system altogether, like me for instance, and do not feel
  810.  > ashamed to say that centers of pixels are a better place for the point for
  811.  > the sake of symmetry alone.
  812.  
  813. How does this help if you draw a two pixel-wide line?
  814.  
  815. Herb Poppe                 National Center for Atmospheric Research (NCAR)
  816. hpoppe@ncar.ucar.edu       1850 Table Mesa Dr.
  817. (303) 497-1296             Boulder, CO  80303
  818.  
  819. ---------------------------
  820.  
  821. From: tom@mills.edu (Tom Erbe)
  822. Subject: My MyDoubleBackProc() is too slow!!
  823. Date: 14 Jan 1993 23:58:46 GMT
  824. Organization: Mills College, Oakland CA
  825.  
  826.  
  827. I am the author of a program which reads and writes many different formats
  828. of soundfiles.  I though (naively) that I would simply add a play function.
  829. I need to play back both 8 and 16 bit, signed and unsigned samples.  I have
  830. most everything working, but it is just a hair too slow to eliminate
  831. clicking. I believe that my loops to convert signed to unsigned are the
  832. problem.  Or rather, these loops probably account for most of the
  833. processing time and I would benefit most if they were optimized.
  834.  
  835. here is the part of my code that contains the loop (from MyDoubleBackProc()):
  836. - ----
  837. switch(inSI.packMode)
  838. {
  839.     case SF_FORMAT_LINEAR_8:
  840.         FSRead(inSI.dFileNum, &sizeRead, charBlock);
  841.         for(i=0; i < SIZE_BLOCK; i++)
  842.             doubleBuffer->dbSoundData[i] = charBlock[i] + 128;
  843.             break;
  844.     case SF_FORMAT_LINEAR_16:
  845.         FSRead(inSI.dFileNum, &sizeRead, shortBlock);
  846.         etcetera.....
  847. - ----
  848.  
  849. Is anyone well enough versed on mac and 680x0 optimization tricks to help
  850. me with this one?  BTW, my code is in Think C 5.0 and most of it is based
  851. on the example code on pages 22-72 to 22-77 of IM VI.
  852.  
  853. Thank you very much,
  854.  
  855. - -- 
  856. tom erbe 
  857. ccm - mills college
  858. 5000 macarthur blvd.
  859. oakland, ca 94613
  860.  
  861. +++++++++++++++++++++++++++
  862.  
  863. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  864. Date: 15 Jan 93 00:48:26 GMT
  865. Organization: Kalamazoo College
  866.  
  867. tom@mills.edu (Tom Erbe) writes:
  868. >
  869. >I have
  870. >most everything working, but it is just a hair too slow to eliminate
  871. >clicking. I believe that my loops to convert signed to unsigned are the
  872. >problem.  Or rather, these loops probably account for most of the
  873. >processing time and I would benefit most if they were optimized.
  874.  
  875. I don't know about that...I would imagine that the FSRead takes up most
  876. of the time.
  877.  
  878. >    case SF_FORMAT_LINEAR_8:
  879. >        FSRead(inSI.dFileNum, &sizeRead, charBlock);
  880. >        for(i=0; i < SIZE_BLOCK; i++)
  881. >            doubleBuffer->dbSoundData[i] = charBlock[i] + 128;
  882. >        break;
  883.  
  884. Adding 128 to a byte and throwing away the overflow is the same thing as
  885. inverting its hi bit, that is, EORing the byte with 0x80.  So the
  886. fastest way to do that loop, I think, would be:
  887.  
  888. {
  889.    register short i;
  890.    register long scratch;
  891.    register long *src, *dest;
  892.    register long constHex80808080;
  893.    src = &doubleBuffer->dbSoundData[0];
  894.    dest = &charBlock[0];
  895.    i = SIZE_BLOCK / 4 - 1;
  896.    constHex80808080 = 0x80808080;
  897.    asm {
  898. @loopStart:
  899.       move.l    (src)+, scratch
  900.       eor.l     constHex80808080, scratch
  901.       move.l    scratch, (dest)+
  902.       dbra      i, @loopStart
  903.    }
  904. }
  905.  
  906. This assumes that SIZE_BLOCK is evenly divisible by four, and that it's
  907. between 4 and 262,140 (so that i won't overflow).
  908.  
  909. I would think it would be faster to eor the constant directly into
  910. memory, but eor doesn't seem to want to take an auto-incrementing
  911. argument in its destination, so it would come out to three instructions
  912. anyway.  I haven't actually counted the cycles, but I'd guess the above
  913. solution is the fastest.
  914. - -- 
  915.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  916.  "The most dishonest, lying people I've ever met are homosexuals.  There
  917.   probably are some honest homosexuals out there -- but so few as to be
  918.   irrelevant."     - Clayton E. Cramer, three days after Christmas, 1992
  919.  
  920. +++++++++++++++++++++++++++
  921.  
  922. From: jimc@tau-ceti.isc-br.com (Jim Cathey)
  923. Date: 15 Jan 93 02:21:35 GMT
  924. Organization: Olivetti North America, Spokane, WA
  925.  
  926. In article <1993Jan15.004826.11474@hobbes.kzoo.edu> k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  927. >I would think it would be faster to eor the constant directly into
  928. >memory, but eor doesn't seem to want to take an auto-incrementing
  929. >argument in its destination, so it would come out to three instructions
  930. >anyway.  I haven't actually counted the cycles, but I'd guess the above
  931. >solution is the fastest.
  932.  
  933. It should work, my ref card shows EOR.L Dn,(An)+ as taking 20 cycles
  934. on the 68010.
  935.  
  936.  
  937. - -- 
  938. +----------------+
  939. ! II      CCCCCC !  Jim Cathey
  940. ! II  SSSSCC     !  ISC-Bunker Ramo
  941. ! II      CC     !  TAF-C8;  Spokane, WA  99220
  942. ! IISSSS  CC     !  UUCP: uunet!isc-br!jimc (jimc@isc-br.isc-br.com)
  943. ! II      CCCCCC !  (509) 927-5757
  944. +----------------+
  945.             One Design to rule them all; one Design to find them.
  946.             One Design to bring them all and in the darkness bind
  947.             them.  In the land of Mediocrity where the PC's lie.
  948.  
  949. +++++++++++++++++++++++++++
  950.  
  951. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  952. Organization: Kalamazoo College
  953. Date: Fri, 15 Jan 1993 04:46:57 GMT
  954.  
  955. jimc@tau-ceti.isc-br.com (Jim Cathey) writes:
  956. >k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  957. >>...eor doesn't seem to want to take an auto-incrementing
  958. >>argument in its destination...[so] I'd guess the above
  959. >>solution is the fastest.
  960. >
  961. >It should work, my ref card shows EOR.L Dn,(An)+ as taking 20 cycles
  962. >on the 68010.
  963.  
  964. You're right.  My way of testing these things is to try them in Think C
  965. in the background.  I must have done something wrong, 'coz it works now.
  966.  
  967. Still believing that the FSRead is taking most of the time, I amend
  968. my code to:
  969.  
  970. {
  971.    register long *src, *dest;
  972.    register short i;
  973.    register long constHex80808080;
  974.    src = &doubleBuffer->dbSoundData[0];
  975.    dest = &charBlock[0];
  976.    i = SIZE_BLOCK / 4 - 1;
  977.    constHex80808080 = 0x80808080;
  978.    asm {
  979. @loopStart:
  980.       move.l    (src)+, (dest)
  981.       eor.l     constHex80808080, (dest)+
  982.       dbra      i, @loopStart
  983.    }
  984. }
  985. - -- 
  986.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  987.  "This sounds like a semantico-psychological backwardization of the
  988.   real world image."                                   - Dave Bloom
  989.  
  990. +++++++++++++++++++++++++++
  991.  
  992. From: christer@cs.umu.se (Christer Ericson)
  993. Date: 15 Jan 93 16:42:11 GMT
  994. Organization: Dep. of Info.Proc, Umea Univ., Sweden
  995.  
  996. In <1993Jan15.044657.23465@hobbes.kzoo.edu> k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  997. >
  998. >[...]
  999. >
  1000. >Still believing that the FSRead is taking most of the time, I amend
  1001. >my code to:
  1002. >
  1003. >[...]
  1004. >      move.l    (src)+, (dest)
  1005. >      eor.l     constHex80808080, (dest)+
  1006. >[...]
  1007.  
  1008. I wouldn't do that if I were you. The first piece of code you wrote was
  1009. faster, and I really do think that it is better to have a marginally
  1010. faster code, than saving a whopping 2 bytes of code in this case.
  1011.  
  1012. The cycle time calculations are given below:
  1013.  
  1014.     MOVE.L    (A0)+,D0    ;12c    MOVE.L    (A0)+,(A1)    ;20c
  1015.     EOR.L    D1,D0        ;6c    EOR.L    D1,(A1)+    ;20c
  1016.     MOVE.L    D0,(A1)+    ;12c                -----
  1017.                 -----                40c
  1018.                 30c
  1019.  
  1020. It is almost always the case that code using more memory accesses
  1021. is slower than code using less memory accesses, just like above.
  1022.  
  1023.  
  1024. Christer Ericson --- Internet: christer@cs.umu.se --- tel: +46-90-166794
  1025. Department of Computer Science, University of Umea, S-90187 UMEA, SWEDEN
  1026.  
  1027. ---------------------------
  1028.  
  1029. End of C.S.M.P. Digest
  1030. **********************
  1031.